package TestController;

import static org.junit.Assert.*;
import java.util.ArrayList;
import org.junit.Test;
import Task28.Command;
import Task28.Controller;
import Task28.Result;

public class TestCd {

	Result result = new Result();
	Command command = new Command();
	Controller tester = new Controller();

	private void init() {
		command.setNameCommand("cd");
		command.setWorkDir("C:\\TEST2");
	}

	@Test
	public void test() {
		init();
		String[] args = null;
		command.setArgs(args);

		result = tester.getResult(command);
		ArrayList<String> aResult = new ArrayList<String>();
		aResult = result.getErrors();

		assertTrue(!aResult.isEmpty());
	}

	@Test
	public void test1() {
		init();
		String[] args = { "" };
		command.setArgs(args);

		result = tester.getResult(command);
		ArrayList<String> aResult = new ArrayList<String>();
		aResult = result.getErrors();

		assertTrue(aResult.isEmpty());
	}

	@Test
	public void test2() {
		init();
		String[] args = { "", "" };
		command.setArgs(args);

		result = tester.getResult(command);
		ArrayList<String> aResult = new ArrayList<String>();
		aResult = result.getErrors();

		assertTrue(!aResult.isEmpty());
	}

	@Test
	public void test3() {
		init();
		String[] args = { "C:\\TEST2" };
		command.setArgs(args);

		result = tester.getResult(command);
		ArrayList<String> aResult = new ArrayList<String>();
		aResult = result.getErrors();

		assertTrue(aResult.isEmpty());
	}

	@Test
	public void test4() {
		init();
		String[] args = { "C:\\TEST2\\a" };
		command.setArgs(args);

		result = tester.getResult(command);
		ArrayList<String> aResult = new ArrayList<String>();
		aResult = result.getErrors();

		assertTrue(aResult.isEmpty());
	}
	
	@Test
	public void test5() {
		init();
		String[] args = { "C:\\TEST2\\a.txt" };
		command.setArgs(args);

		result = tester.getResult(command);
		ArrayList<String> aResult = new ArrayList<String>();
		aResult = result.getErrors();

		assertTrue(!aResult.isEmpty());
	}
	
	@Test
	public void test6() {
		init();
		String[] args = { "E:\\TEST2\\" };
		command.setArgs(args);

		result = tester.getResult(command);
		ArrayList<String> aResult = new ArrayList<String>();
		aResult = result.getErrors();

		assertTrue(aResult.isEmpty());
	}
	@Test
	public void test7() {
		init();
		String[] args = { "C:\\TEST2\\notExist" };
		command.setArgs(args);

		result = tester.getResult(command);
		ArrayList<String> aResult = new ArrayList<String>();
		aResult = result.getErrors();

		assertTrue(!aResult.isEmpty());
	}
	@Test
	public void test8() {
		init();
		String[] args = { };
		command.setArgs(args);

		result = tester.getResult(command);
		ArrayList<String> aResult = new ArrayList<String>();
		aResult = result.getErrors();

		assertTrue(aResult.isEmpty());
	}
	@Test
	public void test9() {
		init();
		String[] args = { "1111" };
		command.setArgs(args);

		result = tester.getResult(command);
		ArrayList<String> aResult = new ArrayList<String>();
		aResult = result.getErrors();

		assertTrue(aResult.isEmpty());
	}
	@Test
	public void test10() {
		init();
		String[] args = { "a.txt" };
		command.setArgs(args);

		result = tester.getResult(command);
		ArrayList<String> aResult = new ArrayList<String>();
		aResult = result.getErrors();

		assertTrue(!aResult.isEmpty());
	}
	@Test
	public void test11() {
		init();
		String[] args = { "1111\\2" };
		command.setArgs(args);

		result = tester.getResult(command);
		ArrayList<String> aResult = new ArrayList<String>();
		aResult = result.getErrors();

		assertTrue(aResult.isEmpty());
	}
	@Test
	public void test12() {
		init();
		String[] args = { ".." };
		command.setArgs(args);

		result = tester.getResult(command);
		ArrayList<String> aResult = new ArrayList<String>();
		aResult = result.getExceptions();

		assertTrue(aResult.isEmpty());
	}
	@Test
	public void test13() {
		init();
		String[] args = { "..//.." };
		command.setArgs(args);

		result = tester.getResult(command);
		ArrayList<String> aResult = new ArrayList<String>();
		aResult = result.getErrors();

		assertTrue(aResult.isEmpty());
	}
}
